package dav.mobile.garuda.states.game.objects.encounters;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;

import dav.mobile.garuda.components.ResourceManager;
import dav.mobile.garuda.components.SoundManager;
import dav.mobile.garuda.states.game.objects.Garuda;

public class Lumping extends Encounter {
	//Outer bounds
	private float m_BoundWidth;
	private float m_BoundHeight;
	
	//Attributes
	private float m_Speed;
	
	//Default constructor
	public Lumping(int x, int y, int color,
			Vector2 force, float speed) {
		//Super
		super(x, y, color, force);
		
		//Generate texture based on color
		m_Texture = ResourceManager.m_LumpingSprite[color];
		
		//Get outer bounds
		m_BoundWidth = 0.5f * m_Texture.getRegionWidth();
		m_BoundHeight = 0.5f * m_Texture.getRegionHeight();
		
		//Set speed
		m_Speed = speed;
	}

	@Override
	public void Update(float deltatime) {
		//Move horizontally
		m_Position.x += deltatime * m_Speed;
	}

	@Override
	public void Render(SpriteBatch m_Spritebatch) {
		//Draw
		m_Spritebatch.draw(m_Texture, getPosX(), getPosY());
	}

	//Check outer bounds and implisitly act
	@Override
	public boolean DoesAABBOuterHit(Garuda garuda) {
		//Init
		boolean m_Hit = false;
		
		float xMin = getPosX() - m_BoundWidth;
		float yMin = getPosY() - m_BoundHeight;
		float xMax = getPosX() + (float) getWidth() + m_BoundWidth;
		float yMax = getPosY() + (float) getHeight() + m_BoundHeight;
		
		float garudaX = garuda.getPosX() + (float) garuda.getWidth();
		float garudaY = garuda.getPosY() + (float) garuda.getHeight();
		
		//Check collision
		m_Hit = !(xMin>garudaX||xMax<garuda.getPosX()||yMin>garudaY||yMax<garuda.getPosY());
		
		//Change angle if true
		if (m_Hit) {}
		
		//Return
		return m_Hit;
	}

	@Override
	protected void PlaySound() {
		SoundManager.PlaySFX(SoundManager.m_LumpingSound);
	}
}
